﻿using System;
using System.Collections.Generic;
using System.Linq;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Data.SqlServerCe;
using System.Diagnostics;

namespace Investafinance.Sync.Shell
{
    /// <summary>
    /// Обалочка для outlook item полей (доступ к колекции полей как стандартных так и новых осуществляется через обект этого класса)
    /// </summary>
    public class ShellFieldItem<ItemType> where ItemType : class
    {
        

        private ItemType ItemOtlook;
        public Dictionary<string, string> collectionField = null;

        private string scon;
        private string nameTable;

        public void UpdateItemOtlook(ItemType ItemOtlook)
        {
            this.ItemOtlook = ItemOtlook;
        }

        public void Update()
        {
            collectionField = new Dictionary<string, string>();
            //пордключимся к бд и создадим экземпляры набора полей прочитанные из методанных бд 
            SqlCeConnection conn = new SqlCeConnection(scon);
            try
            {
                //открываем подключение к бызе
                conn.Open();
                SqlCeCommand cmd;
                string s = "select Name from MetaData_" + nameTable;
                cmd = new SqlCeCommand(s, conn);
                SqlCeDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    collectionField.Add(dr["Name"].ToString(), "");
                }
                dr.Close();
            }
            catch (Exception err)
            {
                if (err.Message.IndexOf("MetaData_"+nameTable) == -1)
                {
                    Debug.Assert(false, "ShellFieldItem.cs Update()" + "\n" + err.Message + "\n -->" + err.Source + "\n"); 
                }
            }
            finally
            {
                //закрываем подключение к базе 
                conn.Close();
                conn.Dispose();
                conn = null;
            }
        }


        /// <summary>
        /// Конструктор
        /// </summary>
        /// <param name="scon">Строка конекта к БД !=Null && !=""</param>
        /// <param name="nameTable">Название синхронизируемой таблици (должно совподать с названием листа SharePoint) !=Null && !=""</param>
        /// <param name="Item">Указатель на обьект  Item текущего сообщения</param>
        public ShellFieldItem(string scon, string nameTable, ItemType Item,string[,] fieldMap)
        {
            Debug.Assert(scon != null, "ShellFieldItem.cs конструктор scon != null");
            Debug.Assert(scon != "", "ShellFieldItem.cs конструктор scon != ''");
            Debug.Assert(nameTable != null, "ShellFieldItem.cs конструктор nameTable != null");
            Debug.Assert(nameTable != "", "ShellFieldItem.cs конструктор nameTable != ''");

            this.scon = scon;
            this.nameTable = nameTable;
            ItemOtlook = Item;
            this.Update();
            associateMap = fieldMap;
        }

        public string[,] associateMap;

        public ShellFieldItem(ItemType Item,string[,] fieldMap)
        {
            ItemOtlook = Item;
            collectionField = new Dictionary<string, string>();
            associateMap = fieldMap;
        }

        public void AddField(string sName,string sValue)
        {
            if (collectionField !=null)
            {
                collectionField.Add(sName, sValue);
            }
        }


        //получить значение по номеру
        public string GetValueField(int i)
        {
            return collectionField.Values.ElementAt(i);
        }

        //установить значение по номеру
        public void SetValueField(int i,string value)
        {
            collectionField[this.GetNameField(i)] = value;
            return;
        }

        //получить имя поля по номеру
        public string GetNameField(int i)
        {
            return collectionField.Keys.ElementAt(i);
        }

        //узнать количество полей
        public int GetCountField()
        {
            return collectionField.Count;
        }

        //Получить ассоциированое имя
        public static string GetAssociateName(string nameInSharePoint,string[,] fieldMap)
        {
            string[,] data = fieldMap;
            if (data != null)
            {
                for (int i = 0; i < Convert.ToInt32(data.Length / 4); i++)
                {
                    if (data[i, 0] == nameInSharePoint)
                    {
                        return data[i, 1];
                    }
                }
            }
            return null;
        }

        //Получить ассоциированое имя
        public static string GetAssociateNameSP(string nameInOutlook,string[,] fieldMap)
        {
            string[,] data = fieldMap;
            if (data != null)
            {
                for (int i = 0; i < Convert.ToInt32(data.Length / 4); i++)
                {
                    if (data[i, 1] == nameInOutlook)
                    {
                        return data[i, 0];
                    }
                }
            }
            return null;
        }

        //  получить значение поля Outlook по String
        public string this[string nameOutlookField]
        {
            get 
            {
                if (ItemOtlook is Outlook.TaskItem)
                {
                    Outlook.TaskItem TaskItem = (Outlook.TaskItem)ItemOtlook;
                    //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                    // и значение collectionField
                    switch (nameOutlookField)
                    {
                        case "EntryID":
                            return TaskItem.EntryID;
                        case "Mileage":
                            return TaskItem.Mileage;
                        case "StartDate":
                            return TaskItem.StartDate.ToString();
                        case "DueDate":
                            return TaskItem.DueDate.ToString();
                        case "Subject":
                            return TaskItem.Subject;
                        case "Body":
                            return TaskItem.Body;
                        case "Completed":
                            return TaskItem.Complete.ToString();
                        case "ActualWork":
                            return TaskItem.ActualWork.ToString();
                        case "BillingInformation":
                            return TaskItem.BillingInformation;
                        case "CardData":
                            return TaskItem.CardData;
                        case "Categories":
                            return TaskItem.Categories;
                        case "Companies":
                            return TaskItem.Companies;
                        case "ContactNames":
                            return TaskItem.ContactNames;
                        case "Contacts":
                            return TaskItem.Contacts;
                        case "InternetCodepage":
                            return TaskItem.InternetCodepage.ToString();
                        case "MessageClass":
                            return TaskItem.MessageClass;
                        case "NoAging":
                            return TaskItem.NoAging.ToString();
                        case "Ordinal":
                            return TaskItem.Ordinal.ToString();
                        case "PercentComplete":
                            return TaskItem.PercentComplete.ToString();
                        case "ReminderOverrideDefault":
                            return TaskItem.ReminderOverrideDefault.ToString();
                        case "ReminderPlaySound":
                            return TaskItem.ReminderPlaySound.ToString();
                        case "ReminderSet":
                            return TaskItem.ReminderSet.ToString();
                        case "ReminderSoundFile":
                            return TaskItem.ReminderSoundFile; 
                        case "ReminderTime":
                            return TaskItem.ReminderTime.ToString();
                        case "Role":
                            return TaskItem.Role;
                        case "SchedulePlusPriority":
                            return TaskItem.SchedulePlusPriority;
                        case "StatusOnCompletionRecipients":
                            return TaskItem.StatusOnCompletionRecipients;
                        case "TeamTask":
                            return TaskItem.TeamTask.ToString();
                        case "ToDoTaskOrdinal":
                            return TaskItem.ToDoTaskOrdinal.ToString();
                        case "TotalWork":
                            return TaskItem.TotalWork.ToString();
                        case "UnRead":
                            return TaskItem.UnRead.ToString();
                        default:
                            if (nameOutlookField.IndexOf("UserProperties") != -1)
                            {
                                string s = nameOutlookField.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                try
                                {
                                    int i = Convert.ToInt32(s);
                                    return TaskItem.UserProperties[i].Value.ToString();
                                }
                                catch
                                {
                                    return TaskItem.UserProperties[s].Value.ToString();
                                }
                            }
                            else
                                return null;
                    }
                }
                else
                    if (ItemOtlook is Outlook.ContactItem)
                    {
                        Outlook.ContactItem ContactItem = (Outlook.ContactItem)ItemOtlook;
                        //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                        // и значение collectionField
                        switch (nameOutlookField)
                        {
                            case "EntryID":
                                return ContactItem.EntryID;
                            case "FullName":
                                return ContactItem.FullName;
                            case "JobTitle":
                                return ContactItem.JobTitle;
                            case "BusinessAddressCity":
                                return ContactItem.BusinessAddressCity;
                            case "OrganizationalIDNumber":
                                return ContactItem.OrganizationalIDNumber;
                            case "GovernmentIDNumber":
                                return ContactItem.GovernmentIDNumber;
                            case "Email1Address":
                                return ContactItem.Email1Address;
                            case "NickName":
                                return ContactItem.NickName;
                            case "User2":
                                return ContactItem.User2;
                            case "Email2Address":
                                return ContactItem.Email2Address;
                            case "User3":
                                return ContactItem.User3;
                            case "User4":
                                return ContactItem.User4;
                            case "Body":
                                return ContactItem.Body;
                            case "User1":
                                return ContactItem.User1;
                            case "Email1AddressType":
                                return ContactItem.Email1AddressType;
                            case "Email1DisplayName":
                                return ContactItem.Email1DisplayName;
                            case "Email2AddressType":
                                return ContactItem.Email2AddressType;
                            case "Email2DisplayName":
                                return ContactItem.Email2DisplayName;
                            case "Email3AddressType":
                                return ContactItem.Email3AddressType;
                            case "Email3DisplayName":
                                return ContactItem.Email3DisplayName;
                            case "Account":
                                return ContactItem.Account;
                            case "Anniversary":
                                return ContactItem.Anniversary.ToString();
                            case "AssistantName":
                                return ContactItem.AssistantName;
                            case "AssistantTelephoneNumber":
                                return ContactItem.AssistantTelephoneNumber;
                            case "BillingInformation":
                                return ContactItem.BillingInformation;
                            case "Birthday":
                                return ContactItem.Birthday.ToString();
                            case "Business2TelephoneNumber":
                                return ContactItem.Business2TelephoneNumber;
                            case "BusinessAddress":
                                return ContactItem.BusinessAddress;
                            case "BusinessAddressCountry":
                                return ContactItem.BusinessAddressCountry;
                            case "BusinessAddressPostalCode":
                                return ContactItem.BusinessAddressPostalCode;
                            case "BusinessAddressPostOfficeBox":
                                return ContactItem.BusinessAddressPostOfficeBox;
                            case "BusinessAddressState":
                                return ContactItem.BusinessAddressState;
                            case "BusinessAddressStreet":
                                return ContactItem.BusinessAddressStreet;
                            case "BusinessCardLayoutXml":
                                return ContactItem.BusinessCardLayoutXml;
                            case "BusinessFaxNumber":
                                return ContactItem.BusinessFaxNumber;
                            case "BusinessHomePage":
                                return ContactItem.BusinessHomePage;
                            case "BusinessTelephoneNumber":
                                return ContactItem.BusinessTelephoneNumber;
                            case "CallbackTelephoneNumber":
                                return ContactItem.CallbackTelephoneNumber;
                            case "CarTelephoneNumber":
                                return ContactItem.CarTelephoneNumber;
                            case "Categories":
                                return ContactItem.Categories;
                            case "Children":
                                return ContactItem.Children;
                            case "Companies":
                                return ContactItem.Companies;
                            case "CompanyMainTelephoneNumber":
                                return ContactItem.CompanyMainTelephoneNumber;
                            case "CompanyName":
                                return ContactItem.CompanyName;
                            case "ComputerNetworkName":
                                return ContactItem.ComputerNetworkName;
                            case "CustomerID":
                                return ContactItem.CustomerID;
                            case "Department":
                                return ContactItem.Department;
                            case "FileAs":
                                return ContactItem.FileAs;
                            case "FTPSite":
                                return ContactItem.FTPSite;
                            case "Hobby":
                                return ContactItem.Hobby;
                            case "Home2TelephoneNumber":
                                return ContactItem.Home2TelephoneNumber;
                            case "HomeAddress":
                                return ContactItem.HomeAddress;
                            case "HomeAddressCity":
                                return ContactItem.HomeAddressCity;
                            case "HomeAddressCountry":
                                return ContactItem.HomeAddressCountry;
                            case "HomeAddressPostalCode":
                                return ContactItem.HomeAddressPostalCode;
                            case "HomeAddressPostOfficeBox":
                                return ContactItem.HomeAddressPostOfficeBox;
                            case "HomeAddressState":
                                return ContactItem.HomeAddressState;
                            case "HomeAddressStreet":
                                return ContactItem.HomeAddressStreet;
                            case "HomeFaxNumber":
                                return ContactItem.HomeFaxNumber;
                            case "HomeTelephoneNumber":
                                return ContactItem.HomeTelephoneNumber;
                            case "IMAddress":
                                return ContactItem.IMAddress;
                            case "Initials":
                                return ContactItem.Initials;
                            case "InternetFreeBusyAddress":
                                return ContactItem.InternetFreeBusyAddress;
                            case "ISDNNumber":
                                return ContactItem.ISDNNumber;
                            case "Journal":
                                return ContactItem.Journal.ToString();
                            case "Language":
                                return ContactItem.Language;
                            case "LastName":
                                return ContactItem.LastName;
                            case "MailingAddress":
                                return ContactItem.MailingAddress;
                            case "MailingAddressCity":
                                return ContactItem.MailingAddressCity;
                            case "MailingAddressCountry":
                                return ContactItem.MailingAddressCountry;
                            case "MailingAddressPostalCode":
                                return ContactItem.MailingAddressPostalCode;
                            case "MailingAddressPostOfficeBox":
                                return ContactItem.MailingAddressPostOfficeBox;
                            case "MailingAddressState":
                                return ContactItem.MailingAddressState;
                            case "MailingAddressStreet":
                                return ContactItem.MailingAddressStreet;
                            case "ManagerName":
                                return ContactItem.ManagerName;
                            case "MessageClass":
                                return ContactItem.MessageClass;
                            case "MiddleName":
                                return ContactItem.MiddleName;
                            case "Mileage":
                                return ContactItem.Mileage;
                            case "MobileTelephoneNumber":
                                return ContactItem.MobileTelephoneNumber;
                            case "NetMeetingAlias":
                                return ContactItem.NetMeetingAlias;
                            case "NetMeetingServer":
                                return ContactItem.NetMeetingServer;
                            case "NoAging":
                                return ContactItem.NoAging.ToString();
                            case "OfficeLocation":
                                return ContactItem.OfficeLocation;
                            case "OtherAddress":
                                return ContactItem.OtherAddress;
                            case "OtherAddressCity":
                                return ContactItem.OtherAddressCity;
                            case "OtherAddressCountry":
                                return ContactItem.OtherAddressCountry;
                            case "OtherAddressPostalCode":
                                return ContactItem.OtherAddressPostalCode;
                            case "OtherAddressPostOfficeBox":
                                return ContactItem.OtherAddressPostOfficeBox;
                            case "OtherAddressState":
                                return ContactItem.OtherAddressState;
                            case "OtherAddressStreet":
                                return ContactItem.OtherAddressStreet;
                            case "OtherFaxNumber":
                                return ContactItem.OtherFaxNumber;
                            case "OtherTelephoneNumber":
                                return ContactItem.OtherTelephoneNumber;
                            case "PagerNumber":
                                return ContactItem.PagerNumber;
                            case "PersonalHomePage":
                                return ContactItem.PersonalHomePage;
                            case "PrimaryTelephoneNumber":
                                return ContactItem.PrimaryTelephoneNumber;
                            case "Profession":
                                return ContactItem.Profession;
                            case "RadioTelephoneNumber":
                                return ContactItem.RadioTelephoneNumber;
                            case "ReferredBy":
                                return ContactItem.ReferredBy;
                            case "ReminderOverrideDefault":
                                return ContactItem.ReminderOverrideDefault.ToString();
                            case "ReminderPlaySound":
                                return ContactItem.ReminderPlaySound.ToString();
                            case "ReminderSet":
                                return ContactItem.ReminderSet.ToString();
                            case "ReminderSoundFile":
                                return ContactItem.ReminderSoundFile;
                            case "ReminderTime":
                                return ContactItem.ReminderTime.ToString();
                            case "Spouse":
                                return ContactItem.Spouse;
                            case "Subject":
                                return ContactItem.Subject;
                            case "Suffix":
                                return ContactItem.Suffix;
                            case "TaskCompletedDate":
                                return ContactItem.TaskCompletedDate.ToString();
                            case "TaskDueDate":
                                return ContactItem.TaskDueDate.ToString();
                            case "TaskStartDate":
                                return ContactItem.TaskStartDate.ToString();
                            case "TaskSubject":
                                return ContactItem.TaskSubject;
                            case "TelexNumber":
                                return ContactItem.TelexNumber;
                            case "Title":
                                return ContactItem.Title;
                            case "ToDoTaskOrdinal":
                                return ContactItem.ToDoTaskOrdinal.ToString();
                            case "TTYTDDTelephoneNumber":
                                return ContactItem.TTYTDDTelephoneNumber;
                            case "UnRead":
                                return ContactItem.UnRead.ToString();
                            case "UserCertificate":
                                return ContactItem.UserCertificate;
                            case "WebPage":
                                return ContactItem.WebPage;
                            case "YomiCompanyName":
                                return ContactItem.YomiCompanyName;
                            case "YomiFirstName":
                                return ContactItem.YomiFirstName;
                            case "YomiLastName":
                                return ContactItem.YomiLastName;
                            case "FirstName":
                                return ContactItem.FirstName;
                            default:
                                if (nameOutlookField.IndexOf("UserProperties") != -1)
                                {
                                    string s = nameOutlookField.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                    try
                                    {
                                        int i = Convert.ToInt32(s);
                                        return ContactItem.UserProperties[i].Value.ToString();
                                    }
                                    catch
                                    {
                                        return ContactItem.UserProperties[s].Value.ToString();
                                    }
                                }
                                else
                                    return null;
                        }
                    }
                    else
                        if (ItemOtlook is Outlook.NoteItem)
                        {
                            Outlook.NoteItem NoteItem = (Outlook.NoteItem)ItemOtlook;
                            //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                            // и значение collectionField
                            switch (nameOutlookField)
                            {
                                case "EntryID":
                                    return NoteItem.EntryID;
                                case "Body":
                                    return NoteItem.Body;
                                case "Categories":
                                    return NoteItem.Categories;
                                case "Height":
                                    return NoteItem.Height.ToString();
                                case "Left":
                                    return NoteItem.Left.ToString();
                                case "MessageClass":
                                    return NoteItem.MessageClass;
                                case "Top":
                                    return NoteItem.Top.ToString();
                                case "Width":
                                    return NoteItem.Width.ToString();
                                default:
                                    return null;
                            }
                        }
                        else
                            if (ItemOtlook is Outlook.MailItem)
                            {
                                Outlook.MailItem MailItem = (Outlook.MailItem)ItemOtlook;
                                //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                                // и значение collectionField
                                switch (nameOutlookField)
                                {
                                    case "EntryID":
                                        return MailItem.EntryID;
                                    case "AlternateRecipientAllowed":
                                        return MailItem.AlternateRecipientAllowed.ToString();
                                    case "AutoForwarded":
                                        return MailItem.AutoForwarded.ToString();
                                    case "BCC":
                                        return MailItem.BCC;
                                    case "BillingInformation":
                                        return MailItem.BillingInformation;
                                    case "Body":
                                        return MailItem.Body;
                                    case "Categories":
                                        return MailItem.Categories;
                                    case "CC":
                                        return MailItem.CC;
                                    case "Companies":
                                        return MailItem.Companies;
                                    case "DeferredDeliveryTime":
                                        return MailItem.DeferredDeliveryTime.ToString();
                                    case "DeleteAfterSubmit":
                                        return MailItem.DeleteAfterSubmit.ToString();
                                    case "EnableSharedAttachments":
                                        return MailItem.EnableSharedAttachments.ToString();
                                    case "ExpiryTime":
                                        return MailItem.ExpiryTime.ToString();
                                    case "FlagDueBy":
                                        return MailItem.FlagDueBy.ToString();
                                    case "FlagRequest":
                                        return MailItem.FlagRequest;
                                    case "HasCoverSheet":
                                        return MailItem.HasCoverSheet.ToString();
                                    case "HTMLBody":
                                        return MailItem.HTMLBody;
                                    case "InternetCodepage":
                                        return MailItem.InternetCodepage.ToString();
                                    case "IsIPFax":
                                        return MailItem.IsIPFax.ToString();
                                    case "MessageClass":
                                        return MailItem.MessageClass;
                                    case "Mileage":
                                        return MailItem.Mileage;
                                    case "NoAging":
                                        return MailItem.NoAging.ToString();
                                    case "OriginatorDeliveryReportRequested":
                                        return MailItem.OriginatorDeliveryReportRequested.ToString();
                                    case "ReadReceiptRequested":
                                        return MailItem.ReadReceiptRequested.ToString();
                                    case "RecipientReassignmentProhibited":
                                        return MailItem.RecipientReassignmentProhibited.ToString();
                                    case "ReminderOverrideDefault":
                                        return MailItem.ReminderOverrideDefault.ToString();
                                    case "ReminderPlaySound":
                                        return MailItem.ReminderPlaySound.ToString();
                                    case "ReminderSet":
                                        return MailItem.ReminderSet.ToString();
                                    case "ReminderSoundFile":
                                        return MailItem.ReminderSoundFile;
                                    case "ReminderTime":
                                        return MailItem.ReminderTime.ToString();
                                    case "SentOnBehalfOfName":
                                        return MailItem.SentOnBehalfOfName;
                                    case "Subject":
                                        return MailItem.Subject;
                                    case "TaskCompletedDate":
                                        return MailItem.TaskCompletedDate.ToString();
                                    case "TaskDueDate":
                                        return MailItem.TaskDueDate.ToString();
                                    case "TaskStartDate":
                                        return MailItem.TaskStartDate.ToString();
                                    case "TaskSubject":
                                        return MailItem.TaskSubject;
                                    case "To":
                                        return MailItem.To;
                                    case "ToDoTaskOrdinal":
                                        return MailItem.ToDoTaskOrdinal.ToString();
                                    case "UnRead":
                                        return MailItem.UnRead.ToString();
                                    case "VotingOptions":
                                        return MailItem.VotingOptions;
                                    case "VotingResponse":
                                        return MailItem.VotingResponse;
                                    default:
                                        if (nameOutlookField.IndexOf("UserProperties") != -1)
                                        {
                                            string s = nameOutlookField.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                            try
                                            {
                                                int i = Convert.ToInt32(s);
                                                return MailItem.UserProperties[i].Value.ToString();
                                            }
                                            catch
                                            {
                                                return MailItem.UserProperties[s].Value.ToString();
                                            }
                                        }
                                        else
                                            return null;
                                }
                            }
                            else
                                if (ItemOtlook is Outlook.PostItem)
                                {
                                    Outlook.PostItem PostItem = (Outlook.PostItem)ItemOtlook;
                                    //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                                    // и значение collectionField
                                    switch (nameOutlookField)
                                    {
                                        case "EntryID":
                                            return PostItem.EntryID;
                                        case "BillingInformation":
                                            return PostItem.BillingInformation;
                                        case "Body":
                                            return PostItem.Body;
                                        case "Categories":
                                            return PostItem.Categories;
                                        case "Companies":
                                            return PostItem.Companies;
                                        case "ExpiryTime":
                                            return PostItem.ExpiryTime.ToString();
                                        case "HTMLBody":
                                            return PostItem.HTMLBody;
                                        case "InternetCodepage":
                                            return PostItem.InternetCodepage.ToString();
                                        case "MessageClass":
                                            return PostItem.MessageClass;
                                        case "Mileage":
                                            return PostItem.Mileage;
                                        case "NoAging":
                                            return PostItem.NoAging.ToString();
                                        case "ReminderOverrideDefault":
                                            return PostItem.ReminderOverrideDefault.ToString();
                                        case "ReminderPlaySound":
                                            return PostItem.ReminderPlaySound.ToString();
                                        case "ReminderSet":
                                            return PostItem.ReminderSet.ToString();
                                        case "ReminderSoundFile":
                                            return PostItem.ReminderSoundFile;
                                        case "ReminderTime":
                                            return PostItem.ReminderTime.ToString();
                                        case "Subject":
                                            return PostItem.Subject;
                                        case "TaskCompletedDate":
                                            return PostItem.TaskCompletedDate.ToString();
                                        case "TaskDueDate":
                                            return PostItem.TaskDueDate.ToString();
                                        case "TaskStartDate":
                                            return PostItem.TaskStartDate.ToString();
                                        case "TaskSubject":
                                            return PostItem.TaskSubject;
                                        case "ToDoTaskOrdinal":
                                            return PostItem.ToDoTaskOrdinal.ToString();
                                        case "UnRead":
                                            return PostItem.UnRead.ToString();
                                        default:
                                            if (nameOutlookField.IndexOf("UserProperties") != -1)
                                            {
                                                string s = nameOutlookField.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                                try
                                                {
                                                    int i = Convert.ToInt32(s);
                                                    return PostItem.UserProperties[i].Value.ToString();
                                                }
                                                catch
                                                {
                                                    return PostItem.UserProperties[s].Value.ToString();
                                                }
                                            }
                                            else
                                                return null;
                                    }
                                }
                                else
                                    return null;

            
            }



           
        }

        //  Установить значение поля Outlook и в своей колекции или получить значение по ключи в своей колекции
        public string this[string key, string associateKey]
        {

            get { return collectionField[key]; }

            set
            {
                if (ItemOtlook is Outlook.TaskItem)
                {
                    Outlook.TaskItem TaskItem = (Outlook.TaskItem)ItemOtlook;
                    //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                    // и значение collectionField
                    switch (associateKey)
                    {
                        case "ID":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Mileage = value;
                            }
                            break;
                        case "Mileage":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Mileage = value;
                            }
                            break;
                        case "StartDate":
                            if (value != null)
                            {
                                if (value != "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.StartDate = Convert.ToDateTime(value);
                                }
                                else
                                {
                                    collectionField[key] = "01.01.4501 0:00:00";
                                    TaskItem.StartDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                }
                            }
                            break;
                        case "DueDate":
                            if (value != null)
                            {
                                if (value != "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.DueDate = Convert.ToDateTime(value);
                                }
                                else
                                {
                                    collectionField[key] = "01.01.4501 0:00:00";
                                    TaskItem.DueDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                }
                            }
                            break;
                        case "Subject":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Subject = value;
                                //TaskItem.UserProperties[1].Value = value;
                            }
                            break;
                        case "Body":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Body = value;
                            }
                            break;
                        case "Completed":
                            if (value != null)
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.Complete = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.Complete = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.Complete = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.Complete = false;
                                        }
                                if (TaskItem.Complete)
                                    TaskItem.DateCompleted = Convert.ToDateTime(collectionField["DateCompleted"]);
                            }
                            break;
                        case "ActualWork":
                            if (value != null)
                            {
                                if (value == "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.ActualWork = 0;
                                }
                                else
                                {
                                    collectionField[key] = value;
                                    TaskItem.ActualWork = Convert.ToInt32(value);
                                }
                            }
                            break;
                        case "BillingInformation":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.BillingInformation = value;
                            }
                            break;
                        case "CardData":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.CardData = value;
                            }
                            break;
                        case "Categories":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Categories = value;
                            }
                            break;
                        case "Companies":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Companies = value;
                            }
                            break;
                        case "ContactNames":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.ContactNames = value;
                            }
                            break;
                        case "Contacts":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Contacts = value;
                            }
                            break;
                        case "InternetCodepage":
                            if (value != null)
                            {
                                if (value == "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.InternetCodepage = 0;
                                }
                                else
                                {
                                    collectionField[key] = value;
                                    TaskItem.InternetCodepage = Convert.ToInt32(value);
                                }
                            }
                            break;
                        case "MessageClass":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.MessageClass = value;
                            }
                            break;
                        case "NoAging":
                            if (value != null)
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.NoAging = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.NoAging = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.NoAging = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.NoAging = false;
                                        }
                            }
                            break;
                        case "Ordinal":
                            if (value != null)
                            {
                                if (value == "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.Ordinal = 0;
                                }
                                else
                                {
                                    collectionField[key] = value;
                                    TaskItem.Ordinal = Convert.ToInt32(value);
                                }
                            }
                            break;
                        case "PercentComplete":
                            if (value != null)
                            {
                                if (value == "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.PercentComplete = 0;
                                }
                                else
                                {
                                    collectionField[key] = value;
                                    TaskItem.PercentComplete = Convert.ToInt32(value);
                                }
                            }
                            break;
                        case "ReminderOverrideDefault":
                            if (value != null)
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.ReminderOverrideDefault = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.ReminderOverrideDefault = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.ReminderOverrideDefault = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.ReminderOverrideDefault = false;
                                        }
                            }
                            break;
                        case "ReminderPlaySound":
                            if (value != null)
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.ReminderPlaySound = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.ReminderPlaySound = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.ReminderPlaySound = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.ReminderPlaySound = false;
                                        }
                            }
                            break;
                        case "ReminderSet":
                            if (value != null)
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.ReminderSet = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.ReminderSet = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.ReminderSet = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.ReminderSet = false;
                                        }
                            }
                            break;
                        case "ReminderSoundFile":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.ReminderSoundFile = value;
                            }
                            break;
                        case "ReminderTime":
                            if (value != null)
                            {
                                if (value != "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.ReminderTime = Convert.ToDateTime(value);
                                }
                                else
                                {
                                    collectionField[key] = "01.01.4501 0:00:00";
                                    TaskItem.ReminderTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                }
                            }
                            break;
                        case "Role":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.Role = value;
                            }
                            break;
                        case "SchedulePlusPriority":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.SchedulePlusPriority = value;
                            }
                            break;
                        case "StatusOnCompletionRecipients":
                            if (value != null)
                            {
                                collectionField[key] = value;
                                TaskItem.StatusOnCompletionRecipients = value;
                            }
                            break;
                        case "TeamTask":
                            if (value != null)
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.TeamTask = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.TeamTask = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.TeamTask = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.TeamTask = false;
                                        }
                            }
                            break;
                        case "ToDoTaskOrdinal":
                            if (value != null)
                            {
                                if (value != "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.ToDoTaskOrdinal = Convert.ToDateTime(value);
                                }
                                else
                                {
                                    collectionField[key] = "01.01.4501 0:00:00";
                                    TaskItem.ToDoTaskOrdinal = Convert.ToDateTime("01.01.4501 0:00:00");
                                }
                            }
                            break;
                        case "TotalWork":
                            if (value != null)
                            {
                                if (value == "")
                                {
                                    collectionField[key] = value;
                                    TaskItem.TotalWork = 0;
                                }
                                else
                                {
                                    collectionField[key] = value;
                                    TaskItem.TotalWork = Convert.ToInt32(value);
                                }
                            }
                            break;
                        case "UnRead":
                            {
                                if (value == "0")
                                {
                                    collectionField[key] = "false";
                                    TaskItem.UnRead = false;
                                }
                                else
                                    if (value == "1")
                                    {
                                        collectionField[key] = "true";
                                        TaskItem.UnRead = true;
                                    }
                                    else
                                        if ((value == "true") || (value == "false"))
                                        {
                                            collectionField[key] = value;
                                            TaskItem.UnRead = Convert.ToBoolean(value);
                                        }
                                        else
                                        {
                                            collectionField[key] = "false";
                                            TaskItem.UnRead = false;
                                        }
                            }
                            break;
                        default:
                            if (associateKey.IndexOf("UserProperties") != -1)
                            {
                                string s= associateKey.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                try
                                {
                                    int i = Convert.ToInt32(s);
                                    TaskItem.UserProperties[i].Value = value;
                                }
                                catch
                                {
                                    TaskItem.UserProperties[s].Value = value;
                                }
                            }
                            collectionField[key] = value;
                            break;
                    }
                }
                else
                    if (ItemOtlook is Outlook.ContactItem)
                    {
                        Outlook.ContactItem ContactItem = (Outlook.ContactItem)ItemOtlook;
                        //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                        // и значение collectionField
                        switch (associateKey)
                        {
                            case "FullName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.FullName = value;
                                }
                                break;
                            case "JobTitle":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.JobTitle = value;
                                }
                                break;
                            case "BusinessAddressCity":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddressCity = value;
                                }
                                break;
                            case "OrganizationalIDNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OrganizationalIDNumber = value;
                                }
                                break;
                            case "GovernmentIDNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.GovernmentIDNumber = value;
                                }
                                break;
                            case "Email1Address":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email1Address = value;
                                }
                                break;
                            case "NickName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.NickName = value;
                                }
                                break;
                            case "User2":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.User2 = value;
                                }
                                break;
                            case "Email2Address":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email2Address = value;
                                }
                                break;
                            case "User3":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.User3 = value;
                                }
                                break;
                            case "User4":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.User4 = value;
                                }
                                break;
                            case "Body":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Body = value;
                                }
                                break;
                            case "User1":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.User1 = value;
                                }
                                break;
                            case "Email1AddressType":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email1AddressType = value;
                                }
                                break;
                            case "Email1DisplayName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email1DisplayName = value;
                                }
                                break;
                            case "Email2AddressType":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email2AddressType = value;
                                }
                                break;
                            case "Email2DisplayName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email2DisplayName = value;
                                }
                                break;
                            case "Email3AddressType":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email3AddressType = value;
                                }
                                break;
                            case "Email3DisplayName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Email3DisplayName = value;
                                }
                                break;
                            case "Account":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Account = value;
                                }
                                break;
                            case "Anniversary":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.Anniversary = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.Anniversary = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "AssistantName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.AssistantName = value;
                                }
                                break;
                            case "AssistantTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.AssistantTelephoneNumber = value;
                                }
                                break;
                            case "BillingInformation":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BillingInformation = value;
                                }
                                break;
                            case "Birthday":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.Birthday = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.Birthday = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "Business2TelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Business2TelephoneNumber = value;
                                }
                                break;
                            case "BusinessAddress":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddress = value;
                                }
                                break;
                            case "BusinessAddressCountry":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddressCountry = value;
                                }
                                break;
                            case "BusinessAddressPostalCode":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddressPostalCode = value;
                                }
                                break;
                            case "BusinessAddressPostOfficeBox":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddressPostOfficeBox = value;
                                }
                                break;
                            case "BusinessAddressState":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddressState = value;
                                }
                                break;
                            case "BusinessAddressStreet":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessAddressStreet = value;
                                }
                                break;
                            case "BusinessCardLayoutXml":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessCardLayoutXml = value;
                                }
                                break;
                            case "BusinessFaxNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessFaxNumber = value;
                                }
                                break;
                            case "BusinessHomePage":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessHomePage = value;
                                }
                                break;
                            case "BusinessTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.BusinessTelephoneNumber = value;
                                }
                                break;
                            case "CallbackTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.CallbackTelephoneNumber = value;
                                }
                                break;
                            case "CarTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.CarTelephoneNumber = value;
                                }
                                break;
                            case "Categories":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Categories = value;
                                }
                                break;
                            case "Children":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Children = value;
                                }
                                break;
                            case "Companies":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Companies = value;
                                }
                                break;
                            case "CompanyMainTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.CompanyMainTelephoneNumber = value;
                                }
                                break;
                            case "CompanyName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.CompanyName = value;
                                }
                                break;
                            case "ComputerNetworkName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.ComputerNetworkName = value;
                                }
                                break;
                            case "CustomerID":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.CustomerID = value;
                                }
                                break;
                            case "Department":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Department = value;
                                }
                                break;
                            case "FileAs":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.FileAs = value;
                                }
                                break;
                            case "FTPSite":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.FTPSite = value;
                                }
                                break;
                            case "Hobby":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Hobby = value;
                                }
                                break;
                            case "Home2TelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Home2TelephoneNumber = value;
                                }
                                break;
                            case "HomeAddress":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddress = value;
                                }
                                break;
                            case "HomeAddressCity":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddressCity = value;
                                }
                                break;
                            case "HomeAddressCountry":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddressCountry = value;
                                }
                                break;
                            case "HomeAddressPostalCode":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddressPostalCode = value;
                                }
                                break;
                            case "HomeAddressPostOfficeBox":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddressPostOfficeBox = value;
                                }
                                break;
                            case "HomeAddressState":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddressState = value;
                                }
                                break;
                            case "HomeAddressStreet":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeAddressStreet = value;
                                }
                                break;
                            case "HomeFaxNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeFaxNumber = value;
                                }
                                break;
                            case "HomeTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.HomeTelephoneNumber = value;
                                }
                                break;
                            case "IMAddress":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.IMAddress = value;
                                }
                                break;
                            case "Initials":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Initials = value;
                                }
                                break;
                            case "InternetFreeBusyAddress":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.InternetFreeBusyAddress = value;
                                }
                                break;
                            case "ISDNNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.ISDNNumber = value;
                                }
                                break;
                            case "Journal":
                                if (value != null)
                                {
                                    if (value == "0")
                                    {
                                        collectionField[key] = "false";
                                        ContactItem.Journal = false;
                                    }
                                    else
                                        if (value == "1")
                                        {
                                            collectionField[key] = "true";
                                            ContactItem.Journal = true;
                                        }
                                        else
                                            if ((value == "true") || (value == "false"))
                                            {
                                                collectionField[key] = value;
                                                ContactItem.Journal = Convert.ToBoolean(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "false";
                                                ContactItem.Journal = false;
                                            }
                                }
                                break;
                            case "Language":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Language = value;
                                }
                                break;
                            case "LastName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.LastName = value;
                                }
                                break;
                            case "MailingAddress":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddress = value;
                                }
                                break;
                            case "MailingAddressCity":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddressCity = value;
                                }
                                break;
                            case "MailingAddressCountry":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddressCountry = value;
                                }
                                break;
                            case "MailingAddressPostalCode":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddressPostalCode = value;
                                }
                                break;
                            case "MailingAddressPostOfficeBox":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddressPostOfficeBox = value;
                                }
                                break;
                            case "MailingAddressState":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddressState = value;
                                }
                                break;
                            case "MailingAddressStreet":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MailingAddressStreet = value;
                                }
                                break;
                            case "ManagerName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.ManagerName = value;
                                }
                                break;
                            case "MessageClass":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MessageClass = value;
                                }
                                break;
                            case "MiddleName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MiddleName = value;
                                }
                                break;
                            case "Mileage":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Mileage = value;
                                }
                                break;
                            case "MobileTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.MobileTelephoneNumber = value;
                                }
                                break;
                            case "NetMeetingAlias":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.NetMeetingAlias = value;
                                }
                                break;
                            case "NetMeetingServer":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.NetMeetingServer = value;
                                }
                                break;
                            case "NoAging":
                                if (value != null)
                                {
                                    if (value == "0")
                                    {
                                        collectionField[key] = "false";
                                        ContactItem.NoAging = false;
                                    }
                                    else
                                        if (value == "1")
                                        {
                                            collectionField[key] = "true";
                                            ContactItem.NoAging = true;
                                        }
                                        else
                                            if ((value == "true") || (value == "false"))
                                            {
                                                collectionField[key] = value;
                                                ContactItem.NoAging = Convert.ToBoolean(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "false";
                                                ContactItem.NoAging = false;
                                            }
                                }
                                break;
                            case "OfficeLocation":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OfficeLocation = value;
                                }
                                break;
                            case "OtherAddress":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddress = value;
                                }
                                break;
                            case "OtherAddressCity":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddressCity = value;
                                }
                                break;
                            case "OtherAddressCountry":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddressCountry = value;
                                }
                                break;
                            case "OtherAddressPostalCode":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddressPostalCode = value;
                                }
                                break;
                            case "OtherAddressPostOfficeBox":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddressPostOfficeBox = value;
                                }
                                break;
                            case "OtherAddressState":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddressState = value;
                                }
                                break;
                            case "OtherAddressStreet":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherAddressStreet = value;
                                }
                                break;
                            case "OtherFaxNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherFaxNumber = value;
                                }
                                break;
                            case "OtherTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.OtherTelephoneNumber = value;
                                }
                                break;
                            case "PagerNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.PagerNumber = value;
                                }
                                break;
                            case "PersonalHomePage":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.PersonalHomePage = value;
                                }
                                break;
                            case "PrimaryTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.PrimaryTelephoneNumber = value;
                                }
                                break;
                            case "Profession":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Profession = value;
                                }
                                break;
                            case "RadioTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.RadioTelephoneNumber = value;
                                }
                                break;
                            case "ReferredBy":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.ReferredBy = value;
                                }
                                break;
                            case "ReminderOverrideDefault":
                                if (value != null)
                                {
                                    if (value == "0")
                                    {
                                        collectionField[key] = "false";
                                        ContactItem.ReminderOverrideDefault = false;
                                    }
                                    else
                                        if (value == "1")
                                        {
                                            collectionField[key] = "true";
                                            ContactItem.ReminderOverrideDefault = true;
                                        }
                                        else
                                            if ((value == "true") || (value == "false"))
                                            {
                                                collectionField[key] = value;
                                                ContactItem.ReminderOverrideDefault = Convert.ToBoolean(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "false";
                                                ContactItem.ReminderOverrideDefault = false;
                                            }
                                }
                                break;
                            case "ReminderPlaySound":
                                if (value != null)
                                {
                                    if (value == "0")
                                    {
                                        collectionField[key] = "false";
                                        ContactItem.ReminderPlaySound = false;
                                    }
                                    else
                                        if (value == "1")
                                        {
                                            collectionField[key] = "true";
                                            ContactItem.ReminderPlaySound = true;
                                        }
                                        else
                                            if ((value == "true") || (value == "false"))
                                            {
                                                collectionField[key] = value;
                                                ContactItem.ReminderPlaySound = Convert.ToBoolean(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "false";
                                                ContactItem.ReminderPlaySound = false;
                                            }
                                }
                                break;
                            case "ReminderSet":
                                if (value != null)
                                {
                                    if (value == "0")
                                    {
                                        collectionField[key] = "false";
                                        ContactItem.ReminderSet = false;
                                    }
                                    else
                                        if (value == "1")
                                        {
                                            collectionField[key] = "true";
                                            ContactItem.ReminderSet = true;
                                        }
                                        else
                                            if ((value == "true") || (value == "false"))
                                            {
                                                collectionField[key] = value;
                                                ContactItem.ReminderSet = Convert.ToBoolean(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "false";
                                                ContactItem.ReminderSet = false;
                                            }
                                }
                                break;
                            case "ReminderSoundFile":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.ReminderSoundFile = value;
                                }
                                break;
                            case "ReminderTime":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.ReminderTime = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.ReminderTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "Spouse":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Spouse = value;
                                }
                                break;
                            case "Subject":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Subject = value;
                                }
                                break;
                            case "Suffix":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Suffix = value;
                                }
                                break;
                            case "TaskCompletedDate":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.TaskCompletedDate = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.TaskCompletedDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "TaskDueDate":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.TaskDueDate = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.TaskDueDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "TaskStartDate":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.TaskStartDate = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.TaskStartDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "TaskSubject":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.TaskSubject = value;
                                }
                                break;
                            case "TelexNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.TelexNumber = value;
                                }
                                break;
                            case "Title":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.Title = value;
                                }
                                break;
                            case "ToDoTaskOrdinal":
                                if (value != null)
                                {
                                    if (value != "")
                                    {
                                        collectionField[key] = value;
                                        ContactItem.ToDoTaskOrdinal = Convert.ToDateTime(value);
                                    }
                                    else
                                    {
                                        collectionField[key] = "01.01.4501 0:00:00";
                                        ContactItem.ToDoTaskOrdinal = Convert.ToDateTime("01.01.4501 0:00:00");
                                    }
                                }
                                break;
                            case "TTYTDDTelephoneNumber":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.TTYTDDTelephoneNumber = value;
                                }
                                break;
                            case "UnRead":
                                if (value != null)
                                {
                                    if (value == "0")
                                    {
                                        collectionField[key] = "false";
                                        ContactItem.UnRead = false;
                                    }
                                    else
                                        if (value == "1")
                                        {
                                            collectionField[key] = "true";
                                            ContactItem.UnRead = true;
                                        }
                                        else
                                            if ((value == "true") || (value == "false"))
                                            {
                                                collectionField[key] = value;
                                                ContactItem.UnRead = Convert.ToBoolean(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "false";
                                                ContactItem.UnRead = false;
                                            }
                                }
                                break;
                            case "UserCertificate":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.UserCertificate = value;
                                }
                                break;
                            case "WebPage":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.WebPage = value;
                                }
                                break;
                            case "YomiCompanyName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.YomiCompanyName = value;
                                }
                                break;
                            case "YomiFirstName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.YomiFirstName = value;
                                }
                                break;
                            case "FirstName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.FirstName = value;
                                }
                                break;
                            case "YomiLastName":
                                if (value != null)
                                {
                                    collectionField[key] = value;
                                    ContactItem.YomiLastName = value;
                                }
                                break;
                            default:
                                if (associateKey.IndexOf("UserProperties") != -1)
                                {
                                    string s = associateKey.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                    try
                                    {
                                        int i = Convert.ToInt32(s);
                                        ContactItem.UserProperties[i].Value = value;
                                    }
                                    catch
                                    {
                                        ContactItem.UserProperties[s].Value = value;
                                    }
                                }
                                collectionField[key] = value;
                                break;
                        }
                    }
                    else
                        if (ItemOtlook is Outlook.NoteItem)
                        {
                            Outlook.NoteItem NoteItem = (Outlook.NoteItem)ItemOtlook;
                            //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                            // и значение collectionField
                            switch (associateKey)
                            {
                                case "Body":
                                    if (value != null)
                                    {
                                        collectionField[key] = value;
                                        NoteItem.Body = value;
                                    }
                                    break;
                                case "Categories":
                                    if (value != null)
                                    {
                                        collectionField[key] = value;
                                        NoteItem.Categories = value;
                                    }
                                    break;
                                case "Height":
                                    if (value != null)
                                    {
                                        if (value == "")
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Height = 0;
                                        }
                                        else
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Height = Convert.ToInt32(value);
                                        }
                                    }
                                    break;
                                case "Left":
                                    if (value != null)
                                    {
                                        if (value == "")
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Left = 0;
                                        }
                                        else
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Left = Convert.ToInt32(value);
                                        }
                                    }
                                    break;
                                case "MessageClass":
                                    if (value != null)
                                    {
                                        collectionField[key] = value;
                                        NoteItem.MessageClass = value;
                                    }
                                    break;
                                case "Top":
                                    if (value != null)
                                    {
                                        if (value == "")
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Top = 0;
                                        }
                                        else
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Top = Convert.ToInt32(value);
                                        }
                                    }
                                    break;
                                case "Width":
                                    if (value != null)
                                    {
                                        if (value == "")
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Width = 0;
                                        }
                                        else
                                        {
                                            collectionField[key] = value;
                                            NoteItem.Width = Convert.ToInt32(value);
                                        }
                                    }
                                    break;
                                default:
                                    collectionField[key] = value;
                                    break;
                            }
                        }
                        else
                            if (ItemOtlook is Outlook.MailItem)
                            {
                                Outlook.MailItem MailItem = (Outlook.MailItem)ItemOtlook;
                                //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                                // и значение collectionField
                                switch (associateKey)
                                {
                                    case "AlternateRecipientAllowed":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.AlternateRecipientAllowed = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.AlternateRecipientAllowed = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.AlternateRecipientAllowed = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.AlternateRecipientAllowed = false;
                                                    }
                                        }
                                        break;
                                    case "AutoForwarded":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.AutoForwarded = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.AutoForwarded = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.AutoForwarded = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.AutoForwarded = false;
                                                    }
                                        }
                                        break;
                                    case "BCC":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.BCC = value;
                                        }
                                        break;
                                    case "BillingInformation":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.BillingInformation = value;
                                        }
                                        break;
                                    case "Body":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.Body = value;
                                        }
                                        break;
                                    case "Categories":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.Categories = value;
                                        }
                                        break;
                                    case "CC":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.CC = value;
                                        }
                                        break;
                                    case "Companies":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.Companies = value;
                                        }
                                        break;
                                    case "DeferredDeliveryTime":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.DeferredDeliveryTime = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.DeferredDeliveryTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "DeleteAfterSubmit":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.DeleteAfterSubmit = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.DeleteAfterSubmit = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.DeleteAfterSubmit = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.DeleteAfterSubmit = false;
                                                    }
                                        }
                                        break;
                                    case "EnableSharedAttachments":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.EnableSharedAttachments = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.EnableSharedAttachments = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.EnableSharedAttachments = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.EnableSharedAttachments = false;
                                                    }
                                        }
                                        break;
                                    case "ExpiryTime":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.ExpiryTime = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.ExpiryTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "FlagDueBy":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.FlagDueBy = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.FlagDueBy = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "FlagRequest":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.FlagRequest = value;
                                        }
                                        break;
                                    case "HasCoverSheet":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.HasCoverSheet = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.HasCoverSheet = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.HasCoverSheet = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.HasCoverSheet = false;
                                                    }
                                        }
                                        break;
                                    case "HTMLBody":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.HTMLBody = value;
                                        }
                                        break;
                                    case "InternetCodepage":
                                        if (value != null)
                                        {
                                            if (value == "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.InternetCodepage = 0;
                                            }
                                            else
                                            {
                                                collectionField[key] = value;
                                                MailItem.InternetCodepage = Convert.ToInt32(value);
                                            }
                                        }
                                        break;
                                    case "IsIPFax":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.IsIPFax = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.IsIPFax = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.IsIPFax = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.IsIPFax = false;
                                                    }
                                        }
                                        break;
                                    case "MessageClass":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.MessageClass = value;
                                        }
                                        break;
                                    case "Mileage":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.Mileage = value;
                                        }
                                        break;
                                    case "NoAging":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.NoAging = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.NoAging = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.NoAging = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.NoAging = false;
                                                    }
                                        }
                                        break;
                                    case "OriginatorDeliveryReportRequested":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.OriginatorDeliveryReportRequested = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.OriginatorDeliveryReportRequested = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.OriginatorDeliveryReportRequested = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.OriginatorDeliveryReportRequested = false;
                                                    }
                                        }
                                        break;
                                    case "ReadReceiptRequested":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.ReadReceiptRequested = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.ReadReceiptRequested = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.ReadReceiptRequested = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.ReadReceiptRequested = false;
                                                    }
                                        }
                                        break;
                                    case "RecipientReassignmentProhibited":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.RecipientReassignmentProhibited = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.RecipientReassignmentProhibited = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.RecipientReassignmentProhibited = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.RecipientReassignmentProhibited = false;
                                                    }
                                        }
                                        break;
                                    case "ReminderOverrideDefault":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.ReminderOverrideDefault = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.ReminderOverrideDefault = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.ReminderOverrideDefault = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.ReminderOverrideDefault = false;
                                                    }
                                        }
                                        break;
                                    case "ReminderPlaySound":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.ReminderPlaySound = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.ReminderPlaySound = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.ReminderPlaySound = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.ReminderPlaySound = false;
                                                    }
                                        }
                                        break;
                                    case "ReminderSet":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.ReminderSet = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.ReminderSet = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.ReminderSet = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.ReminderSet = false;
                                                    }
                                        }
                                        break;
                                    case "ReminderSoundFile":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.ReminderSoundFile = value;
                                        }
                                        break;
                                    case "ReminderTime":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.ReminderTime = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.ReminderTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "SentOnBehalfOfName":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.SentOnBehalfOfName = value;
                                        }
                                        break;
                                    case "Subject":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.Subject = value;
                                        }
                                        break;
                                    case "TaskCompletedDate":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.TaskCompletedDate = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.TaskCompletedDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "TaskDueDate":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.TaskDueDate = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.TaskDueDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "TaskStartDate":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.TaskStartDate = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.TaskStartDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "TaskSubject":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.TaskSubject = value;
                                        }
                                        break;
                                    case "To":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.To = value;
                                        }
                                        break;
                                    case "ToDoTaskOrdinal":
                                        if (value != null)
                                        {
                                            if (value != "")
                                            {
                                                collectionField[key] = value;
                                                MailItem.ToDoTaskOrdinal = Convert.ToDateTime(value);
                                            }
                                            else
                                            {
                                                collectionField[key] = "01.01.4501 0:00:00";
                                                MailItem.ToDoTaskOrdinal = Convert.ToDateTime("01.01.4501 0:00:00");
                                            }
                                        }
                                        break;
                                    case "UnRead":
                                        if (value != null)
                                        {
                                            if (value == "0")
                                            {
                                                collectionField[key] = "false";
                                                MailItem.UnRead = false;
                                            }
                                            else
                                                if (value == "1")
                                                {
                                                    collectionField[key] = "true";
                                                    MailItem.UnRead = true;
                                                }
                                                else
                                                    if ((value == "true") || (value == "false"))
                                                    {
                                                        collectionField[key] = value;
                                                        MailItem.UnRead = Convert.ToBoolean(value);
                                                    }
                                                    else
                                                    {
                                                        collectionField[key] = "false";
                                                        MailItem.UnRead = false;
                                                    }
                                        }
                                        break;
                                    case "VotingOptions":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.VotingOptions = value;
                                        }
                                        break;
                                    case "VotingResponse":
                                        if (value != null)
                                        {
                                            collectionField[key] = value;
                                            MailItem.VotingResponse = value;
                                        }
                                        break;
                                    default:
                                        if (associateKey.IndexOf("UserProperties") != -1)
                                        {
                                            string s = associateKey.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                            try
                                            {
                                                int i = Convert.ToInt32(s);
                                                MailItem.UserProperties[i].Value = value;
                                            }
                                            catch
                                            {
                                                MailItem.UserProperties[s].Value = value;
                                            }
                                        }
                                        collectionField[key] = value;
                                        break;
                                }
                            }
                            else
                                if (ItemOtlook is Outlook.PostItem)
                                {
                                    Outlook.PostItem PostItem = (Outlook.PostItem)ItemOtlook;
                                    //Если поле ассоциируемое с полем Outlook то необходимо установить значение соотвецтвующего поля 
                                    // и значение collectionField
                                    switch (associateKey)
                                    {
                                        case "BillingInformation":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.BillingInformation = value;
                                            }
                                            break;
                                        case "Body":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.Body = value;
                                            }
                                            break;
                                        case "Categories":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.Categories = value;
                                            }
                                            break;
                                        case "Companies":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.Companies = value;
                                            }
                                            break;
                                        case "ExpiryTime":
                                            if (value != null)
                                            {
                                                if (value != "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.ExpiryTime = Convert.ToDateTime(value);
                                                }
                                                else
                                                {
                                                    collectionField[key] = "01.01.4501 0:00:00";
                                                    PostItem.ExpiryTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                                }
                                            }
                                            break;
                                        case "HTMLBody":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.HTMLBody = value;
                                            }
                                            break;
                                        case "InternetCodepage":
                                            if (value != null)
                                            {
                                                if (value == "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.InternetCodepage = 0;
                                                }
                                                else
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.InternetCodepage = Convert.ToInt32(value);
                                                }
                                            }
                                            break;
                                        case "MessageClass":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.MessageClass = value;
                                            }
                                            break;
                                        case "Mileage":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.Mileage = value;
                                            }
                                            break;
                                        case "NoAging":
                                            if (value != null)
                                            {
                                                if (value == "0")
                                                {
                                                    collectionField[key] = "false";
                                                    PostItem.NoAging = false;
                                                }
                                                else
                                                    if (value == "1")
                                                    {
                                                        collectionField[key] = "true";
                                                        PostItem.NoAging = true;
                                                    }
                                                    else
                                                        if ((value == "true") || (value == "false"))
                                                        {
                                                            collectionField[key] = value;
                                                            PostItem.NoAging = Convert.ToBoolean(value);
                                                        }
                                                        else
                                                        {
                                                            collectionField[key] = "false";
                                                            PostItem.NoAging = false;
                                                        }
                                            }
                                            break;
                                        case "ReminderOverrideDefault":
                                            if (value != null)
                                            {
                                                if (value == "0")
                                                {
                                                    collectionField[key] = "false";
                                                    PostItem.ReminderOverrideDefault = false;
                                                }
                                                else
                                                    if (value == "1")
                                                    {
                                                        collectionField[key] = "true";
                                                        PostItem.ReminderOverrideDefault = true;
                                                    }
                                                    else
                                                        if ((value == "true") || (value == "false"))
                                                        {
                                                            collectionField[key] = value;
                                                            PostItem.ReminderOverrideDefault = Convert.ToBoolean(value);
                                                        }
                                                        else
                                                        {
                                                            collectionField[key] = "false";
                                                            PostItem.ReminderOverrideDefault = false;
                                                        }
                                            }
                                            break;
                                        case "ReminderPlaySound":
                                            if (value != null)
                                            {
                                                if (value == "0")
                                                {
                                                    collectionField[key] = "false";
                                                    PostItem.ReminderPlaySound = false;
                                                }
                                                else
                                                    if (value == "1")
                                                    {
                                                        collectionField[key] = "true";
                                                        PostItem.ReminderPlaySound = true;
                                                    }
                                                    else
                                                        if ((value == "true") || (value == "false"))
                                                        {
                                                            collectionField[key] = value;
                                                            PostItem.ReminderPlaySound = Convert.ToBoolean(value);
                                                        }
                                                        else
                                                        {
                                                            collectionField[key] = "false";
                                                            PostItem.ReminderPlaySound = false;
                                                        }
                                            }
                                            break;
                                        case "ReminderSet":
                                            if (value != null)
                                            {
                                                if (value == "0")
                                                {
                                                    collectionField[key] = "false";
                                                    PostItem.ReminderSet = false;
                                                }
                                                else
                                                    if (value == "1")
                                                    {
                                                        collectionField[key] = "true";
                                                        PostItem.ReminderSet = true;
                                                    }
                                                    else
                                                        if ((value == "true") || (value == "false"))
                                                        {
                                                            collectionField[key] = value;
                                                            PostItem.ReminderSet = Convert.ToBoolean(value);
                                                        }
                                                        else
                                                        {
                                                            collectionField[key] = "false";
                                                            PostItem.ReminderSet = false;
                                                        }
                                            }
                                            break;
                                        case "ReminderSoundFile":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.ReminderSoundFile = value;
                                            }
                                            break;
                                        case "ReminderTime":
                                            if (value != null)
                                            {
                                                if (value != "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.ReminderTime = Convert.ToDateTime(value);
                                                }
                                                else
                                                {
                                                    collectionField[key] = "01.01.4501 0:00:00";
                                                    PostItem.ReminderTime = Convert.ToDateTime("01.01.4501 0:00:00");
                                                }
                                            }
                                            break;
                                        case "Subject":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.Subject = value;
                                            }
                                            break;
                                        case "TaskCompletedDate":
                                            if (value != null)
                                            {
                                                if (value != "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.TaskCompletedDate = Convert.ToDateTime(value);
                                                }
                                                else
                                                {
                                                    collectionField[key] = "01.01.4501 0:00:00";
                                                    PostItem.TaskCompletedDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                                }
                                            }
                                            break;
                                        case "TaskDueDate":
                                            if (value != null)
                                            {
                                                if (value != "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.TaskDueDate = Convert.ToDateTime(value);
                                                }
                                                else
                                                {
                                                    collectionField[key] = "01.01.4501 0:00:00";
                                                    PostItem.TaskDueDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                                }
                                            }
                                            break;
                                        case "TaskStartDate":
                                            if (value != null)
                                            {
                                                if (value != "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.TaskStartDate = Convert.ToDateTime(value);
                                                }
                                                else
                                                {
                                                    collectionField[key] = "01.01.4501 0:00:00";
                                                    PostItem.TaskStartDate = Convert.ToDateTime("01.01.4501 0:00:00");
                                                }
                                            }
                                            break;
                                        case "TaskSubject":
                                            if (value != null)
                                            {
                                                collectionField[key] = value;
                                                PostItem.TaskSubject = value;
                                            }
                                            break;
                                        case "ToDoTaskOrdinal":
                                            if (value != null)
                                            {
                                                if (value != "")
                                                {
                                                    collectionField[key] = value;
                                                    PostItem.ToDoTaskOrdinal = Convert.ToDateTime(value);
                                                }
                                                else
                                                {
                                                    collectionField[key] = "01.01.4501 0:00:00";
                                                    PostItem.ToDoTaskOrdinal = Convert.ToDateTime("01.01.4501 0:00:00");
                                                }
                                            }
                                            break;
                                        case "UnRead":
                                            if (value != null)
                                            {
                                                if (value == "0")
                                                {
                                                    collectionField[key] = "false";
                                                    PostItem.UnRead = false;
                                                }
                                                else
                                                    if (value == "1")
                                                    {
                                                        collectionField[key] = "true";
                                                        PostItem.UnRead = true;
                                                    }
                                                    else
                                                        if ((value == "true") || (value == "false"))
                                                        {
                                                            collectionField[key] = value;
                                                            PostItem.UnRead = Convert.ToBoolean(value);
                                                        }
                                                        else
                                                        {
                                                            collectionField[key] = "false";
                                                            PostItem.UnRead = false;
                                                        }
                                            }
                                            break;
                                        default:
                                            if (associateKey.IndexOf("UserProperties") != -1)
                                            {
                                                string s = associateKey.Replace("UserProperties", "").Replace("[", "").Replace("]", "");
                                                try
                                                {
                                                    int i = Convert.ToInt32(s);
                                                    PostItem.UserProperties[i].Value = value;
                                                }
                                                catch
                                                {
                                                    PostItem.UserProperties[s].Value = value;
                                                }
                                            }
                                            collectionField[key] = value;
                                            break;
                                    }
                                }
            }

        }
    }
}
